<template>
  <div class="flex-row">
    <help-list  v-ref:list :row="row" @select-changed="selected" @add="add"></help-list>
    <div style="width:50%;" class="flex" v-show="add_model">
      <help-add  v-ref:add ></help-add>
    </div>

  </div>




</template>

<script>
  import * as Util from '../../../../Util'
  export default {
    title: 'HelpManage',
    data () {
      return {
        add_model: false
      }
    },
    methods: {
      add () {
        console.log('你果然收到了事件')
        this.$refs.add.delButton = false
        this.$refs.add.clear()
        this.$refs.add.model.f_operator = Util.f.name
        this.add_model = true
      },
      edit () {
        console.log('你果然收到了编辑事件1')
        // this.num = 45
        // this.add_model = true
      },
      selected (obj) {
        if (obj) {
          this.$refs.add.delButton = true
        }
        console.log('你果然收到了编辑事件')
        this.add_model = true
        console.log('看看吧，不一定是对的：', obj.val)
        this.$refs.add.model.id = obj.val.id
        this.$refs.add.model.f_allowed_user = obj.val.f_allowed_user
        this.$refs.add.model.f_allowed_company = obj.val.f_allowed_company
        console.log('看看吧，不一定是对的：', obj.val.f_allowed_company, this.$refs.add.model.f_allowed_company)
        this.$refs.add.model.f_password = obj.val.f_password
        this.$refs.add.model.f_operator = obj.val.f_operator
        this.$refs.add.model.type = '修改'
      }
    },
    events: {
      'success' (name, row, res) {
        this.add_model = false
        this.num = 100
        this.$refs.list.search()
      },
      'del' (model) {
        console.log('删除进来了')
        this.$showMessage(`确认删除ID为${model.id}的这行数据？`, ['confirm', 'cancel']).then((res) => {
          if (res === 'confirm') {
            this.$LogicService.del(model).then((res) => {
              this.$refs.list.search()
            }).catch(
              (error) => {
                this.alert(error)
              })
          }
        })
      },
      'close' () {
        this.add_model = false
      }
    }
  }
</script>

<style>

</style>
